/* eslint valid-jsdoc: "off" */

'use strict';

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1616921205580_9824';

  // add your middleware config here
  config.middleware = ['serverTimestamp', 'unauthorizedHandler'];

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };

  // 关闭 csrf
  config.security = {
    csrf: {
      enable: false,
    }
  };

  // 设置 File 模式
  config.multipart = {
    mode: 'file',
    fileExtensions: ['.txt']
  };

  // 模板渲染设置
  config.view = {
    defaultExtension: '.ejs',
    defaultViewEngine: 'ejs',
    mapping: {
      '.nj': 'nunjucks',
      '.hbs': 'handlebars',
      '.ejs': 'ejs',
    },
  };

  // mongo 连接配置
  config.mongoose = {
    client: {
      url: 'mongodb://127.0.0.1/zijue-example',
      options: {}
    }
  };

  // mysql 数据库连接配置
  // config.mysql = {
  //   client: {
  //     host: '127.0.0.1',
  //     port: '3306',
  //     user: 'root',
  //     password: '123456',
  //     database: 'egg_learn',
  //   }
  // }

  // 使用 ORM 的方式集成 mysql
  config.sequelize = {
    dialect: 'mysql',
    host: '127.0.0.1',
    port: 3306,
    database: 'egg_learn',
    username: 'root',
    password: '123456',
    delegate: 'sqlModel', // 定义挂载到框架上为ctx.sqlModel
    baseDir: 'sqlModel', // 定义model文件目录app/`${sqlModel}`
  };

  return {
    ...config,
    ...userConfig,
  };
};
